#!/bin/bash



#
#
# 把配置文件里的变量替换成实际值
#
#
#

echo " $2  >  $1"

# cat $2


# cat $1



function replace_vars() {
  eval "cat <<EOF
$(<$2)
EOF
  " > $1
}

replace_vars "$1"  "$2"



#
#
#
###########################################################################################################################################
#
#
# 实际案例
#
# root@b888d11a5fe2:/tmp# echo  ${ipv4_address}
# 172.70.0.61
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# ls
# ip4.conf.templ  replace_vars.sh
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# rm -rf ip4.conf
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# cat ip4.conf.templ
#
#
#  ${ipv4_address}
#
#
#        9
#
#
#
#
#
#
#
#
#
#
#
#
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# cat replace_vars.sh
# #!/bin/bash
#
# echo " $2  >  $1"
#
# cat $2
#
#
# #cat $1
#
#
#
# function replace_vars() {
#   eval "cat <<EOF
# $(<$2)
# EOF
#   " > $1
# }
#
# replace_vars "$1"  "$2"
#
#
#
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# sh      replace_vars.sh  "/tmp/ip4.conf"  "/tmp/ip4.conf.templ"
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# sh 和 source 哪个能用就用哪个
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# 记录输出日志
# root@b888d11a5fe2:/tmp# source  replace_vars.sh  "/tmp/ip4.conf"  "/tmp/ip4.conf.templ"     > ./evn.log  && cat ./evn.log && rm -rf ./evn.log
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# source  replace_vars.sh  "/tmp/ip4.conf"  "/tmp/ip4.conf.templ"
#  /tmp/ip4.conf.templ  >  /tmp/ip4.conf
#
#
#  ${ipv4_address}
#
#
#        9
#
#
#
#
#
#
#
#
#
#
#
#
# root@b888d11a5fe2:/tmp#
# root@b888d11a5fe2:/tmp# 最后的多余未行 会自动去除
# root@b888d11a5fe2:/tmp# cat /tmp/ip4.conf
#
#
#  172.70.0.61
#
#
#        9
# root@b888d11a5fe2:/tmp#
#



